﻿//	Plazes-ASPI is an AS2.0 abstraction of the Plazes (http://www.plazes.com) XMLRPC-API
//		Copyright (C) 2006	Florian Mlodzik
//
//		This library is free software; you can redistribute it and/or
//		modify it under the terms of the GNU Lesser General Public
//		License as published by the Free Software Foundation; either
//		version 2.1 of the License, or (at your option) any later version.
//
//		This library is distributed in the hope that it will be useful,
//		but WITHOUT ANY WARRANTY; without even the implied warranty of
//		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
//		Lesser General Public License for more details.
//
//		You should have received a copy of the GNU Lesser General Public
//		License along with this library; if not, write to the Free Software
//		Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

// svn:keywords
// $URL: http://plazes-aspi.googlecode.com/svn/trunk/src/as2/com/orthogeneric/webapis/plazes/methods/UserMethods.as $
// $Id: UserMethods.as 5 2006-08-07 19:54:11Z florian.mlodzik $

/**
* The UserMethods-class provides abstracted methods for all remote procedures available in the "user" group
*
* @author florian.mlodzik@gmail.com
* @version 1.0
* @see PlazesService#user
* @see <a href="http://api.plazes.com/wiki/index.php/Plazes_API_Documentation" target="_blank">PlazesApi documenation</a>
*/

// import -->
import com.orthogeneric.webapis.plazes.methods.MethodsBase;
import com.orthogeneric.webapis.plazes.PlazesService;
import com.orthogeneric.webapis.plazes.rpc.RPCall;
// <-- import

class com.orthogeneric.webapis.plazes.methods.UserMethods extends MethodsBase 
{
	/**
	* The UserMethods-class constructor.
	* 
	* @param	srvc A reference to the PlazesService-instance compositing this UserMethods-instance
	*/
	public function UserMethods(srvc:PlazesService)
	{
		super(srvc);
		group = "user"; // instance variable inherited from baseclass
	}

	/**
	* The instance-method to invoke the remote "user.friends" procedure call.
	* 
	* @param online A boolean to return only friends being online. Default is false.
	* @see <a href="http://api.plazes.com/wiki/index.php/User.friends" target="_blank">PlazesApi documentation: user.friends</a>
	*/
	public function getFriends(online:Boolean):Void
	{
		online = online == undefined ? false : online;
		RPCall.invoke(this, "getFriends", group + ".friends", online);
	}

	/**
	* The instance-method to invoke the remote "user.history" procedure call.
	* 
	* @param userKey The key of the user the history should be retrieved for
	* @param limit The maximium number of results to return. Default is 10. Maximum is 100.
	* @param (optional) from The date-object representing the starting date of the history. If empty or null defaults to 365 days prior to the ending history date.
	* @param (optional) to The date-object representing the ending date of the history. If empty or null defaults to today.
	* 
	* @see <a href="http://api.plazes.com/wiki/index.php/User.history" target="_blank">PlazesApi documentation: user.trazes</a> 
	*/
	public function getHistory(userKey:String, limit:Number, from:Date, to:Date):Void
	{
		limit = limit == undefined || limit == null ? 10 : limit > 100 ? 100 : limit < 0 ? 10 : limit;
		// really smart param policy ;)
		to = to == undefined || to == null ? new Date() : to;
		if (from == undefined || from == null) {
			from = new Date();
			from.setDate(to.getDate()-365);
		}
		
		RPCall.invoke(this, "getHistory", group + ".history", userKey, limit, from, to);
	}

	/**
	* The instance-method to invoke the remote "user.trazes" procedure call.
	* 
	* @param maxDays The maximum number of days trazes should be returned for. Default is 0. Maximum is 365.
	* @see <a href="http://api.plazes.com/wiki/index.php/User.trazes" target="_blank">PlazesApi documentation: user.trazes</a>
	*/
	public function getTrazes(maxDays:Number):Void
	{
		maxDays = maxDays == undefined ? 0 : maxDays > 365 ? 365 : maxDays < 0 ? 0 : maxDays;
		RPCall.invoke(this, "getTrazes", group + ".trazes", maxDays);
	}
}